using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWTRUSEQ
    {
        public DataRow Convert2WTRUSEQ(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWTRUSEQ(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WRMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WRNAME"] = " ".PadRight(15 ); 
         dwReturn["WRSTATUS"] = " ".PadRight(1 ); 
         dwReturn["WRDESC"] = " ".PadRight(50 ); 
         dwReturn["WRNBRAP"] = " ".PadRight(0 ); 
         dwReturn["WRNBMTR"] = " ".PadRight(0 ); 
         dwReturn["WRMAT1"] = " ".PadRight(20 ); 
         dwReturn["WRMAT2"] = " ".PadRight(20 ); 
         dwReturn["WRMAT3"] = " ".PadRight(20 ); 
         dwReturn["WRMAT4"] = " ".PadRight(20 ); 
         dwReturn["WRMAT5"] = " ".PadRight(20 ); 
         dwReturn["WRSEQ1"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ2"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ3"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ4"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ5"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ6"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ7"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ8"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ9"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ10"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ11"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ12"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ13"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ14"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ15"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ16"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ17"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ18"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ19"] = " ".PadRight(1 ); 
         dwReturn["WRSEQ20"] = " ".PadRight(1 ); 
         dwReturn["WRNUMB1"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB2"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB3"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB4"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB5"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB6"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB7"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB8"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB9"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB10"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB11"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB12"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB13"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB14"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB15"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB16"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB17"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB18"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB19"] = " ".PadRight(0 ); 
         dwReturn["WRNUMB20"] = " ".PadRight(0 ); 
         dwReturn["WRAENZL"] = " ".PadRight(0 ); 
         dwReturn["WRAENB"] = " ".PadRight(8 ); 
         dwReturn["WRAEND"] = " ".PadRight(0 ); 
         dwReturn["WRNEUB"] = " ".PadRight(8 ); 
         dwReturn["WRNEUD"] = " ".PadRight(0 ); 
         dwReturn["WRFILLER"] = " ".PadRight(42 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWTRUSEQ(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWTRUSEQ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWTRUSEQ(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWTRUSEQ(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWTRUSEQ(dwLocal, ITXDBVERSION);
            }
            UpdateWTRUSEQ(dwLocal);
        }
        public void InsertWTRUSEQ(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WTRUSEQ(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWTRUSEQ(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WTRUSEQ WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WTRUSEQ  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WTRUSEQ";
            Return = Result;
            return Return;
        }
        public void DeleteWTRUSEQ(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WTRUSEQ   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWTRUSEQ(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WTRUSEQ SET "
                    +"WRMANDANT= :WRMANDANT,"
                    +"WRNAME= :WRNAME,"
                    +"WRSTATUS= :WRSTATUS,"
                    +"WRDESC= :WRDESC,"
                    +"WRNBRAP= :WRNBRAP,"
                    +"WRNBMTR= :WRNBMTR,"
                    +"WRMAT1= :WRMAT1,"
                    +"WRMAT2= :WRMAT2,"
                    +"WRMAT3= :WRMAT3,"
                    +"WRMAT4= :WRMAT4,"
                    +"WRMAT5= :WRMAT5,"
                    +"WRSEQ1= :WRSEQ1,"
                    +"WRSEQ2= :WRSEQ2,"
                    +"WRSEQ3= :WRSEQ3,"
                    +"WRSEQ4= :WRSEQ4,"
                    +"WRSEQ5= :WRSEQ5,"
                    +"WRSEQ6= :WRSEQ6,"
                    +"WRSEQ7= :WRSEQ7,"
                    +"WRSEQ8= :WRSEQ8,"
                    +"WRSEQ9= :WRSEQ9,"
                    +"WRSEQ10= :WRSEQ10,"
                    +"WRSEQ11= :WRSEQ11,"
                    +"WRSEQ12= :WRSEQ12,"
                    +"WRSEQ13= :WRSEQ13,"
                    +"WRSEQ14= :WRSEQ14,"
                    +"WRSEQ15= :WRSEQ15,"
                    +"WRSEQ16= :WRSEQ16,"
                    +"WRSEQ17= :WRSEQ17,"
                    +"WRSEQ18= :WRSEQ18,"
                    +"WRSEQ19= :WRSEQ19,"
                    +"WRSEQ20= :WRSEQ20,"
                    +"WRNUMB1= :WRNUMB1,"
                    +"WRNUMB2= :WRNUMB2,"
                    +"WRNUMB3= :WRNUMB3,"
                    +"WRNUMB4= :WRNUMB4,"
                    +"WRNUMB5= :WRNUMB5,"
                    +"WRNUMB6= :WRNUMB6,"
                    +"WRNUMB7= :WRNUMB7,"
                    +"WRNUMB8= :WRNUMB8,"
                    +"WRNUMB9= :WRNUMB9,"
                    +"WRNUMB10= :WRNUMB10,"
                    +"WRNUMB11= :WRNUMB11,"
                    +"WRNUMB12= :WRNUMB12,"
                    +"WRNUMB13= :WRNUMB13,"
                    +"WRNUMB14= :WRNUMB14,"
                    +"WRNUMB15= :WRNUMB15,"
                    +"WRNUMB16= :WRNUMB16,"
                    +"WRNUMB17= :WRNUMB17,"
                    +"WRNUMB18= :WRNUMB18,"
                    +"WRNUMB19= :WRNUMB19,"
                    +"WRNUMB20= :WRNUMB20,"
                    +"WRAENZL= :WRAENZL,"
                    +"WRAENB= :WRAENB,"
                    +"WRAEND= :WRAEND,"
                    +"WRNEUB= :WRNEUB,"
                    +"WRNEUD= :WRNEUD,"
                    +"WRFILLER= :WRFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WRMANDANT", OracleType.NVarChar).Value = dwData["WRMANDANT"].ToString(); 
          or1.Parameters.Add("WRNAME", OracleType.NVarChar).Value = dwData["WRNAME"].ToString(); 
          or1.Parameters.Add("WRSTATUS", OracleType.NVarChar).Value = dwData["WRSTATUS"].ToString(); 
          or1.Parameters.Add("WRDESC", OracleType.NVarChar).Value = dwData["WRDESC"].ToString(); 
          or1.Parameters.Add("WRNBRAP", OracleType.NVarChar).Value = dwData["WRNBRAP"].ToString(); 
          or1.Parameters.Add("WRNBMTR", OracleType.NVarChar).Value = dwData["WRNBMTR"].ToString(); 
          or1.Parameters.Add("WRMAT1", OracleType.NVarChar).Value = dwData["WRMAT1"].ToString(); 
          or1.Parameters.Add("WRMAT2", OracleType.NVarChar).Value = dwData["WRMAT2"].ToString(); 
          or1.Parameters.Add("WRMAT3", OracleType.NVarChar).Value = dwData["WRMAT3"].ToString(); 
          or1.Parameters.Add("WRMAT4", OracleType.NVarChar).Value = dwData["WRMAT4"].ToString(); 
          or1.Parameters.Add("WRMAT5", OracleType.NVarChar).Value = dwData["WRMAT5"].ToString(); 
          or1.Parameters.Add("WRSEQ1", OracleType.NVarChar).Value = dwData["WRSEQ1"].ToString(); 
          or1.Parameters.Add("WRSEQ2", OracleType.NVarChar).Value = dwData["WRSEQ2"].ToString(); 
          or1.Parameters.Add("WRSEQ3", OracleType.NVarChar).Value = dwData["WRSEQ3"].ToString(); 
          or1.Parameters.Add("WRSEQ4", OracleType.NVarChar).Value = dwData["WRSEQ4"].ToString(); 
          or1.Parameters.Add("WRSEQ5", OracleType.NVarChar).Value = dwData["WRSEQ5"].ToString(); 
          or1.Parameters.Add("WRSEQ6", OracleType.NVarChar).Value = dwData["WRSEQ6"].ToString(); 
          or1.Parameters.Add("WRSEQ7", OracleType.NVarChar).Value = dwData["WRSEQ7"].ToString(); 
          or1.Parameters.Add("WRSEQ8", OracleType.NVarChar).Value = dwData["WRSEQ8"].ToString(); 
          or1.Parameters.Add("WRSEQ9", OracleType.NVarChar).Value = dwData["WRSEQ9"].ToString(); 
          or1.Parameters.Add("WRSEQ10", OracleType.NVarChar).Value = dwData["WRSEQ10"].ToString(); 
          or1.Parameters.Add("WRSEQ11", OracleType.NVarChar).Value = dwData["WRSEQ11"].ToString(); 
          or1.Parameters.Add("WRSEQ12", OracleType.NVarChar).Value = dwData["WRSEQ12"].ToString(); 
          or1.Parameters.Add("WRSEQ13", OracleType.NVarChar).Value = dwData["WRSEQ13"].ToString(); 
          or1.Parameters.Add("WRSEQ14", OracleType.NVarChar).Value = dwData["WRSEQ14"].ToString(); 
          or1.Parameters.Add("WRSEQ15", OracleType.NVarChar).Value = dwData["WRSEQ15"].ToString(); 
          or1.Parameters.Add("WRSEQ16", OracleType.NVarChar).Value = dwData["WRSEQ16"].ToString(); 
          or1.Parameters.Add("WRSEQ17", OracleType.NVarChar).Value = dwData["WRSEQ17"].ToString(); 
          or1.Parameters.Add("WRSEQ18", OracleType.NVarChar).Value = dwData["WRSEQ18"].ToString(); 
          or1.Parameters.Add("WRSEQ19", OracleType.NVarChar).Value = dwData["WRSEQ19"].ToString(); 
          or1.Parameters.Add("WRSEQ20", OracleType.NVarChar).Value = dwData["WRSEQ20"].ToString(); 
          or1.Parameters.Add("WRNUMB1", OracleType.NVarChar).Value = dwData["WRNUMB1"].ToString(); 
          or1.Parameters.Add("WRNUMB2", OracleType.NVarChar).Value = dwData["WRNUMB2"].ToString(); 
          or1.Parameters.Add("WRNUMB3", OracleType.NVarChar).Value = dwData["WRNUMB3"].ToString(); 
          or1.Parameters.Add("WRNUMB4", OracleType.NVarChar).Value = dwData["WRNUMB4"].ToString(); 
          or1.Parameters.Add("WRNUMB5", OracleType.NVarChar).Value = dwData["WRNUMB5"].ToString(); 
          or1.Parameters.Add("WRNUMB6", OracleType.NVarChar).Value = dwData["WRNUMB6"].ToString(); 
          or1.Parameters.Add("WRNUMB7", OracleType.NVarChar).Value = dwData["WRNUMB7"].ToString(); 
          or1.Parameters.Add("WRNUMB8", OracleType.NVarChar).Value = dwData["WRNUMB8"].ToString(); 
          or1.Parameters.Add("WRNUMB9", OracleType.NVarChar).Value = dwData["WRNUMB9"].ToString(); 
          or1.Parameters.Add("WRNUMB10", OracleType.NVarChar).Value = dwData["WRNUMB10"].ToString(); 
          or1.Parameters.Add("WRNUMB11", OracleType.NVarChar).Value = dwData["WRNUMB11"].ToString(); 
          or1.Parameters.Add("WRNUMB12", OracleType.NVarChar).Value = dwData["WRNUMB12"].ToString(); 
          or1.Parameters.Add("WRNUMB13", OracleType.NVarChar).Value = dwData["WRNUMB13"].ToString(); 
          or1.Parameters.Add("WRNUMB14", OracleType.NVarChar).Value = dwData["WRNUMB14"].ToString(); 
          or1.Parameters.Add("WRNUMB15", OracleType.NVarChar).Value = dwData["WRNUMB15"].ToString(); 
          or1.Parameters.Add("WRNUMB16", OracleType.NVarChar).Value = dwData["WRNUMB16"].ToString(); 
          or1.Parameters.Add("WRNUMB17", OracleType.NVarChar).Value = dwData["WRNUMB17"].ToString(); 
          or1.Parameters.Add("WRNUMB18", OracleType.NVarChar).Value = dwData["WRNUMB18"].ToString(); 
          or1.Parameters.Add("WRNUMB19", OracleType.NVarChar).Value = dwData["WRNUMB19"].ToString(); 
          or1.Parameters.Add("WRNUMB20", OracleType.NVarChar).Value = dwData["WRNUMB20"].ToString(); 
          or1.Parameters.Add("WRAENZL", OracleType.NVarChar).Value = dwData["WRAENZL"].ToString(); 
          or1.Parameters.Add("WRAENB", OracleType.NVarChar).Value = dwData["WRAENB"].ToString(); 
          or1.Parameters.Add("WRAEND", OracleType.NVarChar).Value = dwData["WRAEND"].ToString(); 
          or1.Parameters.Add("WRNEUB", OracleType.NVarChar).Value = dwData["WRNEUB"].ToString(); 
          or1.Parameters.Add("WRNEUD", OracleType.NVarChar).Value = dwData["WRNEUD"].ToString(); 
          or1.Parameters.Add("WRFILLER", OracleType.NVarChar).Value = dwData["WRFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
